package jdk8的特性.练习案例;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author idea
 * @data 2018/9/10
 */
public class StreamExample {

    //全部转换为大写
    public static void main(String[] args) {

        //针对某一项进行处理
        List<String> wordList=Arrays.asList("aaa","bbb","ccc");
        List<String> upperWordList=wordList.stream()
                .map(String::toUpperCase)
                .collect(Collectors.toList());
        for (String s : upperWordList) {
            System.out.println(s);
        }

        //整合
        Stream<List<Integer>> inputStream=Stream.of(
                Arrays.asList(1),
                Arrays.asList(2,3),
                Arrays.asList(4,5,6)
        );
        Stream outputStream=inputStream.flatMap((itemList)->
            itemList.stream());
        List<Integer> list= (List<Integer>) outputStream.collect(Collectors.toList());
        for (Integer obj : list) {
            System.out.println(obj);
        }

        System.out.println("------------");
        //针对数组类型进行处理
        Integer[] sixNums={1,2,3,4,5,6,7};
        Integer[] evens=Stream.of(sixNums).filter(n->n%2==0).toArray(Integer[]::new);
        for (Integer even : evens) {
            System.out.println(even);
        }
    }
}
